package com.market.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.market.base.utils.JsonResult;
import com.market.common.Configuration;
import com.market.common.Constants;
import com.market.helper.AttachHelper;

/**
 * Created with IntelliJ IDEA.
 * Author: Jerry.hu
 * Create: Jerry.hu (14-9-14 16:04)
 * Description:
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/img")
public class ImageController extends BaseController{
	/**
	 * s
	 * @param request 客户端请求
	 * @return
	 * @throws java.io.IOException
	 */
	@RequestMapping(value = "/upload",method = RequestMethod.POST)
	public @ResponseBody
	JsonResult uploadPicture(HttpServletRequest request) throws IOException {
		MultipartHttpServletRequest multipartRequest  =  (MultipartHttpServletRequest) request;
		MultipartFile attachFile =  multipartRequest.getFile("attachFile");
		String url = AttachHelper.saveAttach(request, attachFile, Configuration.getInstance().getAttach_url(), false);
		return JsonResult.OK.put("url",url.replace(Configuration.getInstance().getAttach_url(),Constants.PATH_FILE));
	}
}
